<template>
    <div class="newsInfo-container">
        <!-- 标题 -->
       <h3 class="title">{{ newsInfo.title }}</h3>
       <!-- 子标题 -->
       <p class="subtitle">
            <span>发表时间：{{newsInfo.add_time|dateFormatter}}</span>
            <span>点击：{{newsInfo.click}}次</span>
       </p>
       <hr>
       <!-- 新闻内容区域 -->
       <div v-html="newsInfo.content" class="newsInfo-content">    
       </div>
       <!-- 评论区 -->
      <comment :id="this.id"></comment>
    </div>    
</template>
<script>
import {Toast} from 'mint-ui'
import comment from '../subcomponents/comment.vue'
export default {
    data(){
        return{
            id:this.$route.params.id,
            newsInfo:{
                title:'',
                add_time:'',
                click:'',
                id:'',
                content:''
            }
        }
    },
    created(){
        this.getNewsInfo(); 
    },
    methods:{
        getNewsInfo(){
            this.$http.get('api/getnew/'+this.id).then(result=>{
                var res=result.body;
                if(res.status===0){
                    this.newsInfo=res.message[0];
                }else{
                    Toast({
                        message:"获取新闻信息失败",
                        position:center,
                        duration:2000,
                    })
                }
            })
        }
    },
    components:{
        'comment':comment
    }
}
</script>
<style lang="scss" scoped>
    .title{
        font-size: 16px;
        text-align: center;
        margin: 10px auto;
    }
    .subtitle{
        color:#226aff;
        display:flex;
        justify-content: space-between;
        font-size: 12px;
    }
</style>